package com.es.hr.visitorscore;

import java.lang.reflect.Field;
import java.sql.ResultSet;

import javax.servlet.http.HttpServletRequest;

import com.es.util.db.Dao;
import com.opensymphony.webwork.interceptor.ServletRequestAware;
import com.opensymphony.xwork.ActionSupport;

public class VisitorScoreInsertAction extends ActionSupport implements ServletRequestAware{

	private static final long serialVersionUID = 1L;
	HttpServletRequest request;

	public void setServletRequest(HttpServletRequest paramHttpServletRequest) {
		this.request = paramHttpServletRequest;
	}
	
	public String execute() throws Exception{
		String result = "";
		VisitorScoreBiz visitorBiz = new VisitorScoreBiz();
		
		VisitorScoreBean visitorBean= this.getVisitorScoreBean(request);
		
		boolean res = visitorBiz.insertVisitorScore(visitorBean);
		if(res) {
			result = "success"; 
		} else {
			result = "fail";
		}
		
		return result;
	}
	
	public VisitorScoreBean getVisitorScoreBean(HttpServletRequest request) throws SecurityException, ClassNotFoundException, IllegalArgumentException, IllegalAccessException{
		Field[] fds = Class.forName("com.es.hr.visitorscore.VisitorScoreBean").getDeclaredFields();   
		VisitorScoreBean bean = new VisitorScoreBean();
		 
		  for(int i=0;i<fds.length;i++)   
		  {   
			  String d= fds[i].getName();
			  fds[i].set(bean, request.getParameter(d));
		  }
		  return bean;
	}
	 

}